home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue24 / ntserv / DemoSv2.dpr < prev    next >
Encoding:
Text File  |  1997-07-04  |  2.4 KB  |  72 lines

  1. program DemoSv2;
  2.  
  3. {==============================================================================}
  4. { NT service which demonstrates multiple services in a process.                }
  5. {                                                                              }
  6. { This was written by John Chaytor and accompanies an aticle in 'The Delphi    }
  7. { Magazine'. See that article for a detailed discussion of NT services.        }
  8. {                                                                              }
  9. {==============================================================================}
  10. Uses SysUtils, Classes, Windows, SvcClass, Services, Logging;
  11.  
  12.   procedure DisplayVersionDetails;
  13.   begin
  14.     WriteLn('DemoSv2 Version 1.00');
  15.   end;
  16.  
  17.   procedure DisplaySyntaxOptions;
  18.   begin
  19.     WriteLn('');
  20.     WriteLn('Command syntax options :-');
  21.     WriteLn('');
  22.     WriteLn('DemoSv2 INSTALL');
  23.     WriteLn('DemoSv2 INSTALL <service1> <service2> ...');
  24.     WriteLn('DemoSv2 UNINSTALL');
  25.     WriteLn('DemoSv2 UNINSTALL <service1> <service2> ...');
  26.     WriteLn('DemoSv2 VERSION');
  27.     WriteLn('');
  28.     WriteLn('Do not execute this program without passing a parameter.');
  29.     WriteLn('If you attempt this an error will occur as the program');
  30.     WriteLn('assumes it is running under the control of the SCM.');
  31.     WriteLn('');
  32.   end;
  33.  
  34. var
  35.   I: Integer;
  36.   Option: ShortString;
  37.   ServiceController: TNTServiceController;
  38.   ServiceList: TStrings;
  39.  
  40. begin
  41.   ServiceController := TNTServiceControllerDemo.Create;
  42.   try
  43.     Option := UpperCase(ParamStr(1));
  44.     ServiceList := TStringList.Create;
  45.     For I := 2 to ParamCount do
  46.       ServiceList.Add(UpperCase(ParamStr(I)));
  47.     With ServiceController do
  48.       try
  49.         RegisterService(TService2a);
  50.         RegisterService(TService2b);
  51.         RegisterService(TService2c);
  52.         if Option = '' then
  53.           Connect
  54.         else
  55.           if (Option = 'INSTALL') or (Option = 'I') then
  56.             InstallServices(ServiceList)
  57.           else
  58.             if (Option = 'UNINSTALL') or (Option = 'U') then
  59.               UninstallServices(ServiceList)
  60.             else
  61.               if (Option = 'VERSION') or (Option = 'V') then
  62.                 DisplayVersionDetails
  63.               else
  64.                 DisplaySyntaxOptions;
  65.       finally
  66.         ServiceList.Free;
  67.       end;
  68.   finally
  69.     ServiceController.Free;
  70.   end;
  71. end.
  72.